package com.example.demo.config;

import org.springframework.web.bind.annotation.ExceptionHandler;

import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-31
 * Time: 16:16
 */

@RestControllerAdvice //表示当前类是针对controller的一个通知类
public class MyExceptionAdvice {

    @ExceptionHandler(ArithmeticException.class)
    public HashMap<String,Object> arithmeticExceptionAdvice(ArithmeticException e){
        HashMap<String,Object> result = new HashMap<>();
        result.put("state",-1);
        result.put("data",null);
        result.put("msg","算术异常" + e.getMessage());
        return result;

    }
}
